package cn.school.servlet;

import cn.school.entity.Subject;
import cn.school.service.GradeService;
import cn.school.service.SubjectService;
import cn.school.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//@WebServlet(name = "subjectUpdateServlet",value = "/subjectUpdateServlet")
@WebServlet(value="/subjectUpdateServlet")
public class SubjectUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获得修改后的信息，并保存
    }
    //负责读取信息，展现到form中
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //HttpSession session = request.getSession();

        Long id= StringUtil.toLong(request.getParameter("id"));
        Subject subject = SubjectService.INST.get(id);
        request.setAttribute("subject",subject);
        /////
        //把年级信息传过去
        request.setAttribute("grades", GradeService.INST.findALL());

        //
        request.getRequestDispatcher("/WEB-INF/jsp/subject/updateSubject.jsp").forward(request,response);
        //response.sendRedirect("updateSubject.jsp");
    }
}
